<?php
/**
 * Created by PhpStorm.
 * User: asdf
 * Date: 2021/9/17
 * Time: 19:19
 */
namespace app\ctl;


use app\mode\test\func;
use function core\backto;
use function core\backto2;
use core\lib\Config;
use core\lib\Queryinfom;
use function core\p;
use function core\pplain;
use Extentions\mysql\Db;
use Extentions\template\Template;
use Extentions\upload\Upload;

//文件名 与类名一致  包含绝对路径
//文件名 + c 表示 类
//$claz = '\\'.MODULE.Dirp.'ctl'.Dirp.$strctl.'c';  //namespace
class indexc {
    private $msg;
    private $mode;
    function __construct()
    {
        $this->msg = Queryinfom::Newinstance();
        $this->mode = new func();
    }

    public function index(){
        p("info: 名字想好了,就叫..简单MVC吧(simpleMVC),含义:大道至简");
        p("hello app;here is index");
        p("时间信息测试:".date("Y M D h m s | i n d e "));
        p("GET 参数列表测试:");pplain($this->msg->Getparms());
        p("POST 参数列表测试:");pplain($this->msg->Postparms());
        p("脚本地址:".$this->msg->Scriptself());
        echo "<a href='/run/index/go'>GO SHOPING 期中作业展示(多应用测试)</a><br>";
        echo "<a href='/run/index/now'>时间接口测试</a><br>";
        echo "<a href='/run/index/db'>数据库接口测试</a><br>";
        echo "<a href='/run/index/Tpl'>模板引擎测试</a><br>";
        echo "<a href='/run/index/upload'>文件上传测试</a><br>";
        echo "<a href='/run/index/pam/a/1/b/2'>参数绑定测试</a><br>";
        echo "<a href='/run/index/msg/a/1/b/2'>请求接收测试</a><br>";
        echo "<a href='/run/index/conf'>配置加载测试</a><br>";
        echo "<a href='/run/index/mode'>模型测试</a><br>";
    }

    function go(){
        backto2("/run/MAPP/shop/index/index/");
    }

    /**
     * @method get
     */
    public function now(){
        p(date("Y/m/d h:m:s"));
    }


    public function db(){
        $db = Db::instance();
        $sql = "select * from blog.`user` where uname = ? ";
        $res = $db -> pre_exec($sql,array("asdf"));
        p($res);
    }


    public function Tpl(){
        $rt = Template::Newinstance();
        $rt->assign("data",123);
        $rt->display("index.html");
    }


    public function upload(){
        $rt = Template::Newinstance();
        $rt->displayN("upload.html",__DIR__);
        if (!$this->msg->isFile()){return;}
        try{
            $fi = Upload::Newinstance(APP.Dirp."views".Dirp."static".Dirp."img".Dirp."upload".Dirp);
            $fi->uploadf();
        }catch (\ErrorException $e){
            p($e->getMessage());
        }

    }

    public function  test(){
        $rt = Template::Newinstance();
        $rt->assign("data",escapeshellarg("lv100"));
        $rt->display("index.html");
    }

    public function db2(){
        var_dump($this->msg->get);
        $uname = $this->msg->Getaparm("uname");
        $db = Db::instance();
        $sql = "select * from blog.`user` where uname = '$uname' ";
        $res = $db -> query($sql);
        $rt = Template::Newinstance();
        $rt->assign("data",$res);
        $rt->display("index.html");
    }

    public function pam($a,$b){
        p($a);
        p($b);
    }

    public function msg(){
        p($this->msg->Getparms());
        p($this->msg->Postparms());
        p($this->msg->Fileparms());
        p($this->msg->Baseurl());
        p($this->msg->method);
    }

    function conf(){
        $conf = Config::all("redis");
        p($conf);
    }

    function mode(){
        p($this->mode->ppp());
    }
}




